<template>
  <el-descriptions
      class="margin-top"
      title="课程"
      :column="2"
      border
  >
    <template #extra>
      <el-button @click="dialogFormVisible = true" type="primary" style="margin-right: 10px">新增</el-button>
      <el-dialog v-model="dialogFormVisible" title="新增课程" draggable>
        <el-form :model="form">
          <el-form-item label="课程名称" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off" type="textarea"/>
          </el-form-item>
          <el-form-item label="课程描述" :label-width="formLabelWidth">
            <el-input v-model="form.description" autocomplete="off" type="textarea"/>
          </el-form-item>
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="addCourse">
          新增课程
        </el-button>
      </span>
        </template>
      </el-dialog>
    </template>
  </el-descriptions>

  <!-- Form -->


</template>

<script setup>
import { reactive, ref } from 'vue'
import axios from "axios";
const dialogFormVisible = ref(false)
const formLabelWidth = '140px'

const form = reactive({
  id: '',
  name: '',
  description: '',
})

const addCourse = async () => {
  dialogFormVisible.value = false

  await
      axios.post('/course',form)
          .then(function (res){
            console.log(res.data)
          })
}

</script>

<style scoped>

.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}

.el-descriptions {
  margin-top: 20px;
}
.cell-item {
  display: flex;
  align-items: center;
}
.margin-top {
  margin-top: 20px;
}
.router-link-active {
  text-decoration: none;
  color: #00CC7E;
}
</style>